#include "stdafx.h"
#include "Fakes/FakeD3D10Device.h"
#include "Fakes/FakeD3D10BlendState.h"

DESCRIPTION_10_TEST_SUITE(BlendDescription)

BOOST_FIXTURE_TEST_CASE(Default, TestBlendDescription)
{
	BOOST_REQUIRE_EQUAL(FALSE, m_desc.AlphaToCoverageEnable);
	BOOST_REQUIRE_EQUAL(D3D10_BLEND_ONE, m_desc.SrcBlend);
	BOOST_REQUIRE_EQUAL(D3D10_BLEND_ZERO, m_desc.DestBlend);
	BOOST_REQUIRE_EQUAL(D3D10_BLEND_OP_ADD, m_desc.BlendOp);
	BOOST_REQUIRE_EQUAL(D3D10_BLEND_ONE, m_desc.SrcBlendAlpha);
	BOOST_REQUIRE_EQUAL(D3D10_BLEND_ZERO, m_desc.DestBlendAlpha);
	BOOST_REQUIRE_EQUAL(D3D10_BLEND_OP_ADD, m_desc.BlendOpAlpha);
    for (UINT i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
	{
		BOOST_REQUIRE_EQUAL(FALSE, m_desc.BlendEnable[i]);
		BOOST_REQUIRE_EQUAL(D3D10_COLOR_WRITE_ENABLE_ALL, m_desc.RenderTargetWriteMask[i]);
	}
}

#define BLEND_DESCRIPTION_TEST_CASE(type_, name_, value_) \
	DESCRIPTION_10_TEST_CASE(type_, name_, value_, BlendDescription)

BLEND_DESCRIPTION_TEST_CASE(BOOL, AlphaToCoverageEnable, TRUE)
BLEND_DESCRIPTION_TEST_CASE(D3D10_BLEND, SrcBlend, D3D10_BLEND_ZERO)
BLEND_DESCRIPTION_TEST_CASE(D3D10_BLEND, DestBlend, D3D10_BLEND_ONE)
BLEND_DESCRIPTION_TEST_CASE(D3D10_BLEND_OP, BlendOp, D3D10_BLEND_OP_SUBTRACT)
BLEND_DESCRIPTION_TEST_CASE(D3D10_BLEND, SrcBlendAlpha, D3D10_BLEND_ZERO)
BLEND_DESCRIPTION_TEST_CASE(D3D10_BLEND, DestBlendAlpha, D3D10_BLEND_ONE)
BLEND_DESCRIPTION_TEST_CASE(D3D10_BLEND_OP, BlendOpAlpha, D3D10_BLEND_OP_SUBTRACT)

BOOST_FIXTURE_TEST_CASE(BlendEnable_, TestBlendDescription)
{
	for (UINT i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
	{
		BOOL value = m_desc.BlendEnable_(i, TRUE).BlendEnable[i];
		BOOST_REQUIRE_EQUAL(TRUE, value);
	}
}

BOOST_FIXTURE_TEST_CASE(RenderTargetWriteMask_, TestBlendDescription)
{
	for (UINT i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
	{
		UINT8 value = m_desc.RenderTargetWriteMask_(i, D3D10_COLOR_WRITE_ENABLE_ALPHA).RenderTargetWriteMask[i];
		BOOST_REQUIRE_EQUAL(D3D10_COLOR_WRITE_ENABLE_ALPHA, value);
	}
}

BOOST_FIXTURE_TEST_CASE(Create, TestBlendDescription)
{
	FakeD3D10Device device;
	FakeD3D10BlendState state;
	device.CreateBlendStateFakeResult = &state;
	device.CreateBlendStateFakeHResult = S_OK;
	ID3D10BlendState *result = m_desc.Create(&device);
	BOOST_REQUIRE(device.CreateBlendStateCalled);
	BOOST_REQUIRE_EQUAL(&m_desc, device.CreateBlendStateLastDesc);
	BOOST_REQUIRE_EQUAL(&state, result);
}

BOOST_AUTO_TEST_SUITE_END()
